package 剑指offer;

public class _42连续数组的最大和 {
    public int maxSubArray(int[] nums) {
        if(nums.length <= 0){
            return 0;
        }
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        int max = dp[0];
        for (int i = 1; i < nums.length; i++) {
            //从后往前累加的思想，原数组中每一个值找出它的最大子序列的值
            dp[i] = Math.max(dp[i-1] + nums[i], nums[i]);
            if(max < dp[i]){
                max = dp[i];
            }
        }
        return max;
    }
}
